# Test simMyro

def run():
    wallPic = makePicture("wall.jpg")
    see,gaze = init()
    home = see
    show(see)
    pause(1)
#    show(gaze)
#    pause(1)
    goMap = canGoMap(gaze)
    see,gaze = goFirstDir(goMap)
    show(see)
    pause(1)
#    show(gaze)
#    pause(1)
    while not(rufSame(see,home)):
        goMap = canGoMap(gaze)
        print goMap
        print isNewDir(goMap)
        if isNewDir(goMap):
            see,gaze = goFirstNewDir(goMap)
        else:
            see,gaze = goFirstDir(goMap)
        show(see)
        pause(1)
#        show(gaze)
#        pause(1)
    return 'done'

def isNewDir(gm):
    return gm[0] or gm[1] or gm[3]

def goFirstDir(gm):
    print 'goFirstDir'
    if gm[0]:
        return go(1)
    elif gm[1]:
        R90()
        return go(1)
    elif gm[2]:
        R90()
        R90()
        return go(1)
    elif gm[3]:
        R90()
        R90()
        R90()
        return go(1)
    else:
        print 'ERROR - bad map'
        return 'error'

def goFirstNewDir(gm):
    print 'goFirstNewDir'
    if gm[0]:
        return go(1)
    elif gm[1]:
        R90()
        return go(1)
    elif gm[3]:
        R90()
        R90()
        R90()
        return go(1)
    else:
        print 'ERROR - no New Direction'
        return 'error'

def canGo(roadAhead):
    if isWall(roadAhead):
        return False
    else:
        return True

def canGoMap(gz):
    gmap = [not isWall(gz)]
    for i in range(3):
        road = R90()
        gmap.append(not isWall(road))
    R90()
    return gmap

def goIfCan(roadAhead,see):
    show(roadAhead)
    pause(2)
    if isWall(roadAhead):
        print 'ROTATE'
        gaze = R90()
    else:
        print 'GO 1'
        see,gaze = go(1)
    return see,gaze
